package com.four.dailymanage.chamber.controller;

import com.four.dailymanage.chamber.entity.ChamberReserve;
import com.four.dailymanage.chamber.service.ChamberReserveService;
import com.four.dailymanage.common.bean.ResponseData;
import com.four.dailymanage.common.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/chamber/reserve")
public class ChamberReserveController extends BaseController {
    @Autowired
    ChamberReserveService chamberReserveService;

    //分页查询
    @GetMapping("/page")
    public ResponseData<Object> getReservePage(
                                               @RequestParam("pageNum") int pageNum,
                                               @RequestParam("pageSize")int pageSize,
                                               @RequestParam(value = "cname",required = false) String cname,
                                               @RequestParam(value = "applyDept",required = false)String applyDept,
                                               @RequestParam(value = "reserveStatus",required = false)String reserveStatus,
                                               @RequestParam(value = "startDt",required = false)String startDt,
                                               @RequestParam(value = "applyMan",required = false)String applyMan){
        return returnObject(chamberReserveService.getPageChamberReserve( pageNum,pageSize, cname, applyDept, reserveStatus, startDt, applyMan));
    }

    //添加会议室
    @PostMapping("/add")
    public ResponseData<Boolean> addReser(@RequestBody ChamberReserve chamberReserve){
        System.out.println(chamberReserve);
        return returnBoolean(chamberReserveService.addReserve(chamberReserve));
    }

    //检查是否被占用
    @GetMapping("/check")
    public ResponseData<Object> checkReserveR(
            @RequestParam("cname")String cname,
            @RequestParam("startDt") String startDt,
            @RequestParam("endDt") String endDt
    ){
        return returnObject(chamberReserveService.checkChamberRoom(cname, startDt, endDt));
    }


    //更新预约状态
    @PutMapping("/approve")
    public ResponseData<Boolean> updateReserve(@RequestBody ChamberReserve chamberReserve){
        return returnBoolean(chamberReserveService.update(chamberReserve));
    }

    //拒绝
    @PutMapping("/reject")
    public ResponseData<Boolean> rejectReserve(@RequestBody ChamberReserve chamberReserve){
        return returnBoolean(chamberReserveService.update(chamberReserve));
    }
}
